
function ColorTable(option){
    this.tableName = option.tableName;
    this.opacityMinValue = option.opacityMinValue;
    this.opacityMaxValue = option.opacityMaxValue;
    this.gradientMinOpacity = option.gradientMinOpacity;
    this.gradientMaxOpacity = option.gradientMaxOpacity;
    this.visibleMinValue = option.visibleMinValue;
    this.visibleMaxValue = option.visibleMaxValue;
 }
 
 ColorTable.prototype.setColorTable = function(layer,index){
     if(!Cesium.defined(layer)){
         return;
     }
     var minValue = layer.minValue;
     var maxValue = layer.maxValue;
     var minExtent = this.visibleMinValue;
     var maxExtent = this.visibleMaxValue;
     if(minExtent > maxExtent){
         var temp = minExtent;
         minExtent = maxExtent;
         maxExtent = temp;
     }
     this.setOpacityFunction(layer,minValue,maxValue,minExtent,maxExtent);
     this.setColorFunction(layer,minValue,maxValue,minExtent,maxExtent,index);
 };
 
 ColorTable.prototype.setOpacityFunction = function(layer,minValue,maxValue,minExtent,maxExtent){
     var minOpacity =  this.opacityMinValue;
     var maxOpacity =  this.opacityMaxValue;
     var opacityFunction = new Cesium.PiecewiseFunction();
     opacityFunction.addPoint(minValue, 0.0);
     opacityFunction.addPoint(minValue + (maxValue - minValue) * minExtent, minOpacity);
     opacityFunction.addPoint(minValue + (maxValue - minValue) * maxExtent, maxOpacity);
     opacityFunction.addPoint(minValue + (maxValue - minValue) * (maxExtent + 0.01), minOpacity);
     opacityFunction.addPoint(maxValue, 0.0);
 
     layer.opacityTransferFunction = opacityFunction;
 };
 
 ColorTable.prototype.setColorFunction = function(layer,minValue,maxValue,minExtent,maxExtent,index){
     var colorfun = new Cesium.ColorTransferFunction();
     var extentRange = maxExtent - minExtent;
     var span = extentRange / 15;
 
     switch(index){
         case 1:
             colorfun.addRGBPoint(minValue, 1, 103/255, 103/255);
             colorfun.addRGBPoint(minValue + (maxValue - minValue) * minExtent, 200/255, 160/255, 130/255);
             colorfun.addRGBPoint(minValue + (maxValue - minValue) * (minExtent + span), 180/255, 200/255, 170/255);
             colorfun.addRGBPoint(minValue + (maxValue - minValue) * (minExtent + span * 2), 162/255, 251/255, 194/255);
 //			colorfun.addRGBPoint(minValue + (maxValue - minValue) * (minExtent + span * 3), 9/255, 153/255, 255/255);
 //			colorfun.addRGBPoint(minValue + (maxValue - minValue) * (minExtent + span * 4), 9/255, 204/255, 255/255);
 //			colorfun.addRGBPoint(minValue + (maxValue - minValue) * (minExtent + span * 5), 9/255, 255/255, 255/255);
 //			colorfun.addRGBPoint(minValue + (maxValue - minValue) * (minExtent + span * 6), 51/255, 255/255, 204/255);
 //			colorfun.addRGBPoint(minValue + (maxValue - minValue) * (minExtent + span * 7), 102/255, 255/255, 153/255);
 //			colorfun.addRGBPoint(minValue + (maxValue - minValue) * (minExtent + span * 8), 153/255, 255/255, 102/255);
 //			colorfun.addRGBPoint(minValue + (maxValue - minValue) * (minExtent + span * 9), 204/255, 255/255, 51/255);
 //			colorfun.addRGBPoint(minValue + (maxValue - minValue) * (minExtent + span * 10), 255/255, 255/255, 0);
 //			colorfun.addRGBPoint(minValue + (maxValue - minValue) * (minExtent + span * 11), 255/255, 204/255, 0);
 //			colorfun.addRGBPoint(minValue + (maxValue - minValue) * (minExtent + span * 12), 255/255, 153/255, 0);
 //			colorfun.addRGBPoint(minValue + (maxValue - minValue) * (minExtent + span * 13), 255/255, 102/255, 0);
 //			colorfun.addRGBPoint(minValue + (maxValue - minValue) * (minExtent + span * 14), 255/255, 51/255, 0);
 //			colorfun.addRGBPoint(minValue + (maxValue - minValue) * (minExtent + span * 15), 255/255, 0, 0);
             break;
         case 2:
             colorfun.addRGBPoint(minValue,157/255, 0, 1);
             colorfun.addRGBPoint(minValue + (maxValue - minValue) * minExtent, 165, 50/255, 1);
             colorfun.addRGBPoint(minValue + (maxValue - minValue) * (minExtent + span), 190/255, 100/255, 1);
             colorfun.addRGBPoint(minValue + (maxValue - minValue) * (minExtent + span * 2),230/255, 198/255, 1);
 //			colorfun.addRGBPoint(minValue + (maxValue - minValue) * (minExtent + span * 3), 255/255, 153/255, 255/255);
 //			colorfun.addRGBPoint(minValue + (maxValue - minValue) * (minExtent + span * 4), 255/255, 204/255, 255/255);
 //			colorfun.addRGBPoint(minValue + (maxValue - minValue) * (minExtent + span * 5), 255/255, 255/255, 255/255);
 //			colorfun.addRGBPoint(minValue + (maxValue - minValue) * (minExtent + span * 6), 51/255, 255/255, 204/255);
 //			colorfun.addRGBPoint(minValue + (maxValue - minValue) * (minExtent + span * 7), 102/255, 255/255, 153/255);
 //			colorfun.addRGBPoint(minValue + (maxValue - minValue) * (minExtent + span * 8), 153/255, 255/255, 102/255);
 //			colorfun.addRGBPoint(minValue + (maxValue - minValue) * (minExtent + span * 9), 204/255, 255/255, 51/255);
 //			colorfun.addRGBPoint(minValue + (maxValue - minValue) * (minExtent + span * 10), 255/255, 255/255, 0);
 //			colorfun.addRGBPoint(minValue + (maxValue - minValue) * (minExtent + span * 11), 255/255, 204/255, 0);
 //			colorfun.addRGBPoint(minValue + (maxValue - minValue) * (minExtent + span * 12), 255/255, 153/255, 0);
 //			colorfun.addRGBPoint(minValue + (maxValue - minValue) * (minExtent + span * 13), 255/255, 102/255, 0);
 //			colorfun.addRGBPoint(minValue + (maxValue - minValue) * (minExtent + span * 14), 255/255, 51/255, 0);
 //			colorfun.addRGBPoint(minValue + (maxValue - minValue) * (minExtent + span * 15), 255/255, 0, 0);
             break;
         case 3:
             colorfun.addRGBPoint(minValue, 149/255, 232/255, 249/255);
             colorfun.addRGBPoint(minValue + (maxValue - minValue) * minExtent, 149/255, 232/255, 249/255);
             colorfun.addRGBPoint(minValue + (maxValue - minValue) * (minExtent + span), 70/255, 116/255, 200/255);
             colorfun.addRGBPoint(minValue + (maxValue - minValue) * (minExtent + span * 2), 0, 39/255, 148/255);
             colorfun.addRGBPoint(minValue + (maxValue - minValue) * (minExtent + span * 3), 0, 39/255, 148/255);
 //			colorfun.addRGBPoint(minValue + (maxValue - minValue) * (minExtent + span * 4), 157/255, 204/255, 255/255);
 //			colorfun.addRGBPoint(minValue + (maxValue - minValue) * (minExtent + span * 5), 157/255, 255/255, 255/255);
 //			colorfun.addRGBPoint(minValue + (maxValue - minValue) * (minExtent + span * 6), 51/255, 255/255, 204/255);
 //			colorfun.addRGBPoint(minValue + (maxValue - minValue) * (minExtent + span * 7), 102/255, 255/255, 153/255);
 //			colorfun.addRGBPoint(minValue + (maxValue - minValue) * (minExtent + span * 8), 153/255, 255/255, 102/255);
 //			colorfun.addRGBPoint(minValue + (maxValue - minValue) * (minExtent + span * 9), 204/255, 255/255, 51/255);
 //			colorfun.addRGBPoint(minValue + (maxValue - minValue) * (minExtent + span * 10), 255/255, 255/255, 0);
 //			colorfun.addRGBPoint(minValue + (maxValue - minValue) * (minExtent + span * 11), 255/255, 204/255, 0);
 //			colorfun.addRGBPoint(minValue + (maxValue - minValue) * (minExtent + span * 12), 255/255, 153/255, 0);
 //			colorfun.addRGBPoint(minValue + (maxValue - minValue) * (minExtent + span * 13), 255/255, 102/255, 0);
 //			colorfun.addRGBPoint(minValue + (maxValue - minValue) * (minExtent + span * 14), 255/255, 51/255, 0);
 //			colorfun.addRGBPoint(minValue + (maxValue - minValue) * (minExtent + span * 15), 255/255, 0, 0);
             break;
         case 4:
             colorfun.addRGBPoint(minValue, 186/255, 1, 190/255);
             colorfun.addRGBPoint(minValue + (maxValue - minValue) * minExtent, 186/255, 1, 180/255);
             colorfun.addRGBPoint(minValue + (maxValue - minValue) * (minExtent + span),  106/255, 255/255, 170/255);
             colorfun.addRGBPoint(minValue + (maxValue - minValue) * (minExtent + span * 2),  186/255, 1, 180/255);
             colorfun.addRGBPoint(minValue + (maxValue - minValue) * (minExtent + span * 3),  186/255, 1, 190/255);
 //			colorfun.addRGBPoint(minValue + (maxValue - minValue) * (minExtent + span * 4),  149/255, 204/255, 255/255);
 //			colorfun.addRGBPoint(minValue + (maxValue - minValue) * (minExtent + span * 5),  149/255, 255/255, 255/255);
 //			colorfun.addRGBPoint(minValue + (maxValue - minValue) * (minExtent + span * 6), 51/255, 255/255, 204/255);
 //			colorfun.addRGBPoint(minValue + (maxValue - minValue) * (minExtent + span * 7), 102/255, 255/255, 153/255);
 //			colorfun.addRGBPoint(minValue + (maxValue - minValue) * (minExtent + span * 8), 153/255, 255/255, 102/255);
 //			colorfun.addRGBPoint(minValue + (maxValue - minValue) * (minExtent + span * 9), 204/255, 255/255, 51/255);
 //			colorfun.addRGBPoint(minValue + (maxValue - minValue) * (minExtent + span * 10), 255/255, 255/255, 0);
 //			colorfun.addRGBPoint(minValue + (maxValue - minValue) * (minExtent + span * 11), 255/255, 204/255, 0);
 //			colorfun.addRGBPoint(minValue + (maxValue - minValue) * (minExtent + span * 12), 255/255, 153/255, 0);
 //			colorfun.addRGBPoint(minValue + (maxValue - minValue) * (minExtent + span * 13), 255/255, 102/255, 0);
 //			colorfun.addRGBPoint(minValue + (maxValue - minValue) * (minExtent + span * 14), 255/255, 51/255, 0);
 //			colorfun.addRGBPoint(minValue + (maxValue - minValue) * (minExtent + span * 15), 255/255, 0, 0);
             break;
         default:
             colorfun.addRGBPoint(minValue, 0, 190/255, 255/255);
             colorfun.addRGBPoint(minValue + (maxValue - minValue) * minExtent, 0, 255/255, 180/255);
             colorfun.addRGBPoint(minValue + (maxValue - minValue) * (minExtent + span * 2), 120/255, 250/255, 204/255);
             colorfun.addRGBPoint(minValue + (maxValue - minValue) * (minExtent + span * 3), 0, 102/255, 255/255);
             colorfun.addRGBPoint(minValue + (maxValue - minValue) * (minExtent + span * 4), 0, 153/255, 255/255);
             colorfun.addRGBPoint(minValue + (maxValue - minValue) * (minExtent + span * 5), 0, 204/255, 255/255);
             colorfun.addRGBPoint(minValue + (maxValue - minValue) * (minExtent + span * 6), 0, 255/255, 255/255);
             colorfun.addRGBPoint(minValue + (maxValue - minValue) * (minExtent + span * 7), 51/255, 255/255, 204/255);
             colorfun.addRGBPoint(minValue + (maxValue - minValue) * (minExtent + span * 8), 102/255, 255/255, 153/255);
             colorfun.addRGBPoint(minValue + (maxValue - minValue) * (minExtent + span * 9), 204/255, 255/255, 51/255);
             colorfun.addRGBPoint(minValue + (maxValue - minValue) * (minExtent + span * 10), 255/255, 255/255, 0);
             colorfun.addRGBPoint(minValue + (maxValue - minValue) * (minExtent + span * 11), 255/255, 204/255, 0);
             colorfun.addRGBPoint(minValue + (maxValue - minValue) * (minExtent + span * 12), 255/255, 153/255, 0);
             colorfun.addRGBPoint(minValue + (maxValue - minValue) * (minExtent + span * 13), 255/255, 102/255, 0);
             colorfun.addRGBPoint(minValue + (maxValue - minValue) * (minExtent + span * 14), 255/255, 51/255, 0);
             colorfun.addRGBPoint(minValue + (maxValue - minValue) * (minExtent + span * 15), 255/255, 0, 0);
             break;
     }
 
     if(minExtent + span * 15 < 1.0){
         colorfun.addRGBPoint(maxValue, 255/255, 0, 0);
     }
 
     layer.colorTransferFunction = colorfun;
 };
 
 ColorTable.prototype.setGradientOpacityValue = function(layer){
     var minValue = layer.minValue;
     var maxValue = layer.maxValue;
     var minExtent = this.gradientMinOpacity;
     var maxExtent = this.gradientMaxOpacity;
     if(minExtent > maxExtent){
         var temp = minExtent;
         minExtent = maxExtent;
         maxExtent = temp;
     }
     layer.gradientOpacityMinValue = Math.abs(maxValue - minValue) * 0.1 *minExtent;
     layer.gradientOpacityMaxValue = Math.abs(maxValue - minValue) * 0.1 * maxExtent;
 }